
package com.viweb.storemanager.core;


public class Connection {

    public final static byte POSTGRESSQL = 0;
    public final static byte MYSQL = 1;
    public final static byte DB2 = 2;
    public final static byte ORACLE = 3;
    public final static byte HSQL = 4;
    public final static byte SQLSERVER = 5;
    public final static byte ACCESS = 6;
    private byte db = Connection.POSTGRESSQL;
    private String server = "localhost";
    private String port = "5432";
    private String database = "DBName";
    private String username = "postgres";
    private String password = "postgres";

    /**
     * Creates a new instance of Connection
     */
    public Connection() {
    }

    public Connection(byte db, String server, String port, String database,
            String username, String password) {
        this.setDb(db);
        this.setServer(server);
        this.setPort(port);
        this.setDatabase(database);
        this.setUsername(username);
        this.setPassword(password);
    }

    public byte getDb() {
        return db;
    }

    public void setDb(byte db) {
        this.db = db;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDriver() {
        byte i = this.getDb();

        switch (i) {
            case Connection.POSTGRESSQL:
                return "org.postgresql.Driver";
            case Connection.MYSQL:
                return "com.mysql.jdbc.Driver";
            case Connection.DB2:
                return "com.ibm.db2.jcc.DB2Driver";
            case Connection.ORACLE:
                return "oracle.jdbc.OracleDriver";
            case Connection.HSQL:
                return "org.hsqldb.jdbcDriver";
            case Connection.SQLSERVER:
                return "com.microsoft.jdbc.sqlserver.SQLServerDriver";
            case Connection.ACCESS:
                return "sun.jdbc.odbc.JdbcOdbcDriver";
            default:
                return "org.postgresql.Driver";
        }
    }

    public String getURL() {
        byte i = this.getDb();

        switch (i) {
            case Connection.POSTGRESSQL:
                return "jdbc:postgresql://" +
                        this.getServer() + ":" +
                        this.getPort() + "/" +
                        this.getDatabase();
            case Connection.MYSQL:
                return "jdbc:mysql://" +
                        this.getServer() + ":" +
                        this.getPort() + "/" +
                        this.getDatabase();
            case Connection.DB2:
                return "jdbc:derby:net://" +
                        this.getServer() + ":" +
                        this.getPort() + "/" +
                        this.getDatabase();
            case Connection.ORACLE:
                return "jdbc:oracle:thin:@" +
                        this.getServer() + ":" +
                        this.getPort() + ":" +
                        this.getDatabase();
            case Connection.HSQL:
                return "jdbc:hsqldb:hsql://" +
                        this.getServer() + ":" +
                        this.getPort();
            case Connection.SQLSERVER:
                return "jdbc:microsoft:sqlserver://" +
                        this.getServer() + ":" +
                        this.getPort() + ";DatabaseName=" +
                        this.getDatabase();
            case Connection.ACCESS:
                return "jdbc:odbc:" +
                        "Driver={Microsoft Access Driver (*.mdb)};" +
                        "DBQ=";
            default:
                return "jdbc:postgresql://" +
                        this.getServer() + ":" +
                        this.getPort() + "/" +
                        this.getDatabase();
        }
    }
}